home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / cmds / loadavg / RCS / server.c,v < prev   
Encoding:
Text File  |  1987-11-20  |  6.3 KB  |  302 lines

  1. head     2.1;
  2. access   ;
  3. symbols  ;
  4. locks    ; strict;
  5. comment  @ * @;
  6.  
  7.  
  8. 2.1
  9. date     87.03.11.18.12.49;  author douglis;  state Exp;
  10. branches ;
  11. next     2.0;
  12.  
  13. 2.0
  14. date     87.03.11.12.40.30;  author douglis;  state Exp;
  15. branches ;
  16. next     ;
  17.  
  18.  
  19. desc
  20. @Server process to read named pipe and maintain global system
  21. state.
  22. @
  23.  
  24.  
  25. 2.1
  26. log
  27. @Keep track of whether to migrate processes based on load average
  28. and keyboard/mouse idle time.
  29. @
  30. text
  31. @/*
  32.  * server.c --
  33.  *
  34.  *    Server process to read named pipe and maintain global system
  35.  *        state.
  36.  *
  37.  * Copyright 1987 Regents of the University of California
  38.  * All rights reserved.
  39.  */
  40.  
  41. #ifndef lint
  42. static char rcsid[] = "$Header: server.c,v 2.0 87/03/11 12:40:30 douglis Exp $ SPRITE (Berkeley)";
  43. #endif not lint
  44.  
  45.  
  46. #include "loadAvg.h"
  47. #include "byte.h"
  48.  
  49. static void UpdateData();
  50. static void PrintAllInfo();
  51.  
  52.  
  53. /*
  54.  *----------------------------------------------------------------------
  55.  *
  56.  * RunServer --
  57.  *
  58.  *    (Optionally) fork a child to be the global server.  This daemon will
  59.  *    receive load information from local daemons using named
  60.  *    pipes and respond to requests for lighty-loaded machines.
  61.  *
  62.  * Results:
  63.  *    None.
  64.  *
  65.  * Side effects:
  66.  *    A second process may be created.
  67.  *
  68.  *----------------------------------------------------------------------
  69.  */
  70.  
  71. void
  72. RunServer()
  73. {
  74.     ReturnStatus status;
  75.     NodeInfo nodeInfo[MAX_NUM_HOSTS];
  76.     NodeInfo info;
  77.     Proc_PID pid;
  78.     int requestStreamID;
  79.     int responseStreamID;
  80.     char fileName[FS_MAX_PATH_NAME_LENGTH];
  81.     int i;
  82.     int bytesRead;
  83.     int flags;
  84.     int requestType;
  85.  
  86.  
  87.     if (forkChild) {
  88.     status = Proc_Fork(FALSE, &pid);
  89.     } else {
  90.     status = PROC_CHILD_PROC;
  91.     }
  92.     if (status == PROC_CHILD_PROC) {
  93.     Io_PrintString(fileName, "%s/%s", pipeDir, requestFile);
  94.     flags = FS_READ | FS_NAMED_PIPE_OPEN;
  95.     if (debug) {
  96.         Io_PrintStream(io_StdErr, "Opening file %s.\n", fileName);
  97.         Io_Flush(io_StdErr);
  98.     }
  99.     status = Fs_Open(fileName, flags, 0, &requestStreamID);
  100.     if (status != SUCCESS) {
  101.         Stat_PrintMsg(status, "Error in Fs_Open");
  102.         Proc_Exit(status);
  103.     }
  104.  
  105.     Io_PrintString(fileName, "%s/%s", pipeDir, responseFile);
  106.     flags = FS_WRITE | FS_CREATE | FS_NAMED_PIPE_OPEN;
  107.     if (debug) {
  108.         Io_PrintStream(io_StdErr, "Opening file %s.\n", fileName);
  109.         Io_Flush(io_StdErr);
  110.     }
  111.     status = Fs_Open(fileName, flags, OPEN_MODE, &responseStreamID);
  112.     if (status != SUCCESS) {
  113.         Stat_PrintMsg(status, "Error in Fs_Open");
  114.         Proc_Exit(status);
  115.     }
  116.  
  117.     for (i = 0; i < MAX_NUM_HOSTS; i++) {
  118.         nodeInfo[i].timestamp = NIL;
  119.     }
  120.  
  121.     while(TRUE) {
  122.         status = Fs_Read(requestStreamID, sizeof(NodeInfo),
  123.                  (Address) &info, &bytesRead);
  124.         if (status != SUCCESS) {
  125.         Stat_PrintMsg(status, "Error in Fs_Read");
  126.         Proc_Exit(status);
  127.         }
  128.         if (bytesRead != sizeof(NodeInfo)) {
  129.         Io_PrintStream(io_StdErr, "Only %d bytes read.\n",
  130.                    bytesRead);
  131.         Proc_Exit(FAILURE);
  132.         }
  133.  
  134. #ifdef reallynotdone
  135.         switch (requestType) {
  136.         case LA_RPC_UPDATE: {
  137.             UpdateData(bufPtr, nodeInfo);
  138.             break;
  139.         }
  140.         case LA_RPC_IDLE: {
  141. #ifdef notdone
  142.             PrintIdleNode(nodeInfo);
  143. #else
  144.             PrintAllInfo(nodeInfo);
  145. #endif
  146.             break;
  147.         }
  148.         case LA_RPC_ALL_INFO: {
  149.             PrintAllInfo(nodeInfo);
  150.             break;
  151.         }
  152.         }
  153. #endif reallynotdone
  154.         nodeInfo[info.hostID] = info;
  155.     }
  156.     } else if (status != SUCCESS) {
  157.     Stat_PrintMsg(status, "Error in Proc_Fork");
  158.     Proc_Exit(status);
  159.     }
  160. }
  161.  
  162. #ifdef notdef
  163.  
  164. /*
  165.  *----------------------------------------------------------------------
  166.  *
  167.  * UpdateData --
  168.  *
  169.  *    Update the information for a node.
  170.  *
  171.  * Results:
  172.  *    None.
  173.  *
  174.  * Side effects:
  175.  *    'nodeInfo' is updated for the specified host.
  176.  *
  177.  *----------------------------------------------------------------------
  178.  */
  179.  
  180. static void
  181. UpdateData(bufPtr, nodeInfo)
  182.     char *bufPtr;        /* buffer containing data to be parsed */
  183.     NodeInfo nodeInfo[];    /* pointer to array of per-node data */
  184. {
  185.     int numScanned;
  186.     int hostID;
  187.     NodeInfo info;
  188.  
  189.     numScanned = Io_ScanString(bufPtr,
  190.                    "%d %d %d %d %d %d %lf %lf %lf",
  191.                    &hostID,
  192.                    &info.timestamp,
  193.                    &info.noInput,
  194.                    &info.utils[0],
  195.                    &info.utils[1],
  196.                    &info.utils[2],
  197.                    &info.lengths[0],
  198.                    &info.lengths[1],
  199.                    &info.lengths[2]);
  200.     if (numScanned != 9) {
  201.     Io_PrintStream(io_StdErr,
  202. "Error scanning information from request pipe.  Scanned %d items.\n",
  203.                numScanned);
  204.     Proc_Exit(FAILURE);
  205.     }
  206.     if (hostID <= 0 || hostID >= MAX_NUM_HOSTS) {
  207.     Io_PrintStream(io_StdErr, "Invalid hostID: %d.\n", hostID);
  208.     Proc_Exit(FAILURE);
  209.     }
  210.     if (debug) {
  211.     Io_PrintStream(io_StdErr,
  212.                "Received info from node %d.\n", hostID);
  213.     Io_Flush(io_StdErr);
  214.     }
  215.     nodeInfo[hostID] = info;
  216. }
  217. #endif notdef
  218.  
  219.  
  220. /*
  221.  *----------------------------------------------------------------------
  222.  *
  223.  * PrintAllInfo --
  224.  *
  225.  *    Print statistics for all nodes.
  226.  *
  227.  * Results:
  228.  *    None.
  229.  *
  230.  * Side effects:
  231.  *    Data is written to io_StdOut.
  232.  *
  233.  *----------------------------------------------------------------------
  234.  */
  235.  
  236. static void
  237. PrintAllInfo(nodeInfo)
  238.     NodeInfo nodeInfo[];    /* array of per-node data */
  239. {
  240.     int hostID;
  241.  
  242.     if (debug) {
  243.     Io_PrintStream(io_StdErr,
  244.                "Received request for idle node.\n");
  245.     }
  246.     for (hostID = 0; hostID < MAX_NUM_HOSTS; hostID++) {
  247.     if (nodeInfo[hostID].timestamp != NIL) {
  248.         Io_PrintStream(io_StdErr,
  249.                "%3d %10u %10u %3d %3d %3d %5.2lf %5.2lf %5.2lf\n",
  250.                hostID,
  251.                nodeInfo[hostID].timestamp,
  252.                nodeInfo[hostID].noInput,
  253.                nodeInfo[hostID].utils[0],
  254.                nodeInfo[hostID].utils[1],
  255.                nodeInfo[hostID].utils[2],
  256.                nodeInfo[hostID].lengths[0],
  257.                nodeInfo[hostID].lengths[1],
  258.                nodeInfo[hostID].lengths[2]);
  259.     }
  260.     }
  261.     Io_Flush(io_StdErr);
  262. }
  263.  
  264. @
  265.  
  266.  
  267. 2.0
  268. log
  269. @Initial revision.
  270. @
  271. text
  272. @d12 1
  273. a12 1
  274. static char rcsid[] = "$Header: loadAvg.c,v 1.8 87/03/11 11:09:50 douglis Exp $ SPRITE (Berkeley)";
  275. d46 1
  276. a52 3
  277.     char buffer[UTIL_RECORD_SIZE];
  278.     char *bufPtr;
  279.     int numScanned;
  280. d92 2
  281. a93 2
  282.         status = Fs_Read(requestStreamID, UTIL_RECORD_SIZE, buffer,
  283.                  &bytesRead);
  284. d98 1
  285. a98 1
  286.         if (bytesRead != UTIL_RECORD_SIZE) {
  287. d103 2
  288. a104 9
  289.         bufPtr = buffer;
  290.         numScanned = Io_ScanString(bufPtr, "%2d", &requestType);
  291.         if (numScanned != 1) {
  292.         Io_PrintStream(io_StdErr,
  293.        "Error scanning request type from pipe.  Input string is '%s'.\n",
  294.                    bufPtr);
  295.         Proc_Exit(FAILURE);
  296.         }
  297.         bufPtr += 3;
  298. d123 2
  299. d132 1
  300. d187 1
  301. @
  302.